package com.estate.asset.controller;

import com.estate.asset.service.AssetService;
import com.estate.bean.Device;
import com.estate.bean.Parking;
import com.estate.util.JsonResult;
import com.estate.util.ResultTool;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/asset")
@Slf4j
public class AssetController {

    @Resource
    private AssetService assetService;

    @GetMapping("list/{page}/{size}")
    public JsonResult list(@PathVariable("page") int page, @PathVariable("size") int size) {
        log.info("page:{},size:{}", page, size);
        JsonResult result = assetService.listByPage(page, size);
        log.info("result:{}", result);
        return ResultTool.success(result);
    }

    @PostMapping("/save")
    public JsonResult save(Device device) {
        log.info("新增device:{}", device);
        JsonResult result = assetService.saveDevice(device);
        log.info("result:{}", result);
        return result;
    }

    @PutMapping("/update")
    public JsonResult update(Device device) {
        log.info("修改device:{}", device);
        JsonResult result = assetService.updateDevice(device);
        log.info("result:{}", result);
        return result;
    }

    @DeleteMapping("/delete")
    public JsonResult delete(@RequestParam("deviceId") String deviceId) {
        log.info("删除deviceId:{}", deviceId);
        JsonResult result = assetService.deleteDevice(deviceId);
        log.info("result:{}", result);
        return result;
    }

    @GetMapping("/list/{deviceId}")
    public JsonResult list(@PathVariable("deviceId") String deviceId) {
        log.info("deviceId:{}", deviceId);
        JsonResult result = ResultTool.success(assetService.getById(deviceId));
        log.info("result:{}", result);
        return result;
    }
}
